fix: unify Anthropic/Claude model detection in ProviderTransform#20414
fix: unify Anthropic/Claude model detection in ProviderTransform#20414bussnet wants to merge 2 commits intoanomalyco:devfrom
Conversation
Extract isClaudeModel() helper to replace three inconsistent detection strategies that used different conditions to identify Claude models. The empty-content stripping (L56) only checked api.npm while caching (L282) and tool-ID scrubbing (L76) used broader name-based checks. This mismatch caused 400 prefill errors when Claude models were routed through OpenAI-compatible proxies — caching applied but the required empty-content stripping did not.
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
The test spread from anthropicModel which has id containing 'claude', making isClaudeModel() correctly detect it as Claude despite the overridden providerID and api fields.
|
Reson for the failing e2e-tests: OPENCODE_API_KEY is required when OPENCODE_E2E_REQUIRE_PAID=true — missing secret, not related to this change |
|
This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window. Feel free to open a new pull request that follows our guidelines. |
Summary
isClaudeModel()helper intransform.tsto replace three inconsistent detection strategies for identifying Claude/Anthropic modelsProblem
ProviderTransformuses three different conditions to detect Anthropic/Claude models, and they disagree:api.npm === "@ai-sdk/anthropic"api.id.includes("claude")providerID || api.id || model.id || api.npmWhen a Claude model is accessed through an OpenAI-compatible proxy (
@ai-sdk/openai-compatible), the model name may contain "claude" but the npm package is not@ai-sdk/anthropic. This causes caching and tool-ID scrubbing to activate while empty-content stripping does not. Empty assistant messages survive, get cache metadata attached, and Anthropic rejects them as invalid prefill.Fix
Single
isClaudeModel(model)function used at all three sites:Testing
packages/opencode/src/provider/transform.ts